package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lc.afbx.R;
import com.lc.afbx.adapters.TeamChooseListAdapter;
import com.lc.afbx.conn.GetApiTeamInfomation;
import com.lc.afbx.util.PrefrenceConfig;
import com.zcx.helper.app.AppException;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/5.
 */
public class TeamChooseActivity extends BaseActivity implements View.OnClickListener{

    private ListView team_choose_lv;
    private TeamChooseListAdapter adapter;
    private List<GetApiTeamInfomation.Data> lists = new ArrayList<>();

    private GetApiTeamInfomation getApiTeamInfomation = new GetApiTeamInfomation(new AsyCallBack<GetApiTeamInfomation.Info>() {

        @Override
        public void onSuccess(String toast, int type, GetApiTeamInfomation.Info info) throws Exception {

//            GetApiTeamInfomation.Data data = new GetApiTeamInfomation.Data();
//
//            data.id = "";
//            data.title = "自己的团队";
//
//            lists.add(data);

            lists.addAll(info.dataList);

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_team_choose);

        team_choose_lv = ((ListView) findViewById(R.id.team_choose_lv));

        team_choose_lv.setAdapter(adapter = new TeamChooseListAdapter(context, lists));

        team_choose_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                //数据是使用Intent返回
                Intent intent = new Intent();
                //把返回数据存入Intent
                Bundle bundle = new Bundle();

                bundle.putString("id", lists.get(position).id);
                bundle.putString("title", lists.get(position).title);

                intent.putExtras(bundle);
                //设置返回数据
                TeamChooseActivity.this.setResult(1, intent);

                finish();

            }
        });

        getApiTeamInfomation.userid = getIntent().getStringExtra(PrefrenceConfig.INTENT_TAG);
        getApiTeamInfomation.execute(this);

    }


    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:

                finish();

                break;

        }
    }



}
